from contextlib import asynccontextmanager

from fastapi import FastAPI

from app.api.recipes import router as recipes_router
from app.db import database, engine, metadata

metadata.create_all(engine)


@asynccontextmanager
async def lifespan(app: FastAPI):
    await database.connect()
    yield
    await database.disconnect()


app = FastAPI(
    title="Recipes API",
    description="Простой API приложения для создания и хранения рецептов блюд.",
    lifespan=lifespan,
)


app.include_router(recipes_router)
